<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>07_Canvas-描边颜色</title>
  <style>
    body{
      margin: 0;
      padding: 0;
      background-image: url(../../images/grid.png);
    }
    canvas{
      background-color: rgba(255, 0, 0, 0.1);
    }
  </style>
</head>
<body>

  <canvas id="tutorial" width="300" height="300px">
    你的浏览器不兼容Canvas,请升级您的浏览器!
  </canvas>
  <script>
    window.onload = function(){
      // 1. 获取canvas元素
      var canvas = document.getElementById('tutorial');
      // 2. 获取绘图上下文
      var ctx = canvas.getContext('2d');

      ctx.fillStyle = 'rgba(0, 0, 255, 0.5)';
      ctx.fillRect(10, 10, 100, 100);

      ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
      ctx.strokeRect(50, 50, 100, 100);

      ctx.strokeStyle = 'rgba(0, 255, 0, 0.5)';
      ctx.beginPath();
      ctx.rect(10, 100, 100, 100);
      ctx.stroke(); // 填充颜色
     
    }

  </script>
  
</body>
</html>